package sun.superstring.interface3;

public class ClassDataInterImpl2 implements ClassDateInter {
    private Student [] students; // 记住送来的全班学生信息。
    // 用有参构造器来接
    public ClassDataInterImpl2(Student[] students) {
        this.students = students;
    }

    @Override
    public void printAllStudentsInfos() {
        System.out.println("学生信息如下：");
        int menNum = 0;
        for(int i=0; i<students.length; i++){
            Student s = students[i];
            if(s.getSex() == '男'){
                menNum++;
            }
            System.out.println(s.getName() + " " + s.getSex() + " " + s.getScore());
        }
        System.out.println("男同学人数是：" + menNum + " ,女同学的人数是：" + (students.length - menNum));
    }

    @Override
    public void printAverageScore() {
        System.out.println("平局分如下：");
        Student s1 = students[0];
        double sum = s1.getScore();
        double max = s1.getScore();
        double min = s1.getScore();
        for (int i = 1; i < students.length; i++) {
            Student s = students[i];
            sum += s.getScore();
            if(s.getScore() > max){
                max = s.getScore();
            }
            if(s.getScore() < min){
                min = s.getScore();
            }
        }
        System.out.println("去掉一个最高分：" + max + "，去掉一个最低分：" + min + "\n全班同学平均成绩是：" + (sum - max - min)/ (students.length - 2));
    }
}
